﻿using Shinva.LADModel.Abstractions;
using Shinva.Variables.Interface;
using Shinva.Variables.Models;
using Shinva.Variables.Type.bit;
using Shinva.Variables.Type.character;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shinva.LADModel.Type.MoveOperations
{
    public class S_Move:ElementNodeBase
    {
        public PlcString IN { get;set; }
        public PlcString OUT { get;set; }
        public override PlcBool EN
        {
            get
            {
                return en;
            }
            set
            {
                en = value;
            }
        }
        public override PlcBool ENO
        {
            get
            {

                eno.Value = en.Value && moveValue();
                return eno;
            }
            set
            {
                eno = value;
            }
        }
        public S_Move()
        {
            Name = "S_Move";
            variableTableInterface.AddVariable("IN", StorageType.Input);
            variableTableInterface.AddVariable("OUT", StorageType.Output);
            IN = variableTableInterface.GetVariableValue<PlcString>("IN");
            OUT = variableTableInterface.GetVariableValue<PlcString>("OUT");
        }

        public override IPlcMember GetInterfaceVariableByName(string name)
        {
            if (name == "out") return OUT;
            else if (name == "in") return IN;
            else return variableTableInterface.GetVariableValue<IPlcMember>(name);
        }
        public bool moveValue()
        {
            if (IN == null || OUT == null)
            {
                return false;
            }
            else
            {
                   OUT.Value = IN.Value;
                return true;
            }
        }
    }
}
